<?php
global $wpdb;
global $ts_dbversion;
$ts_dbversion = "0.01";

global $table_ranges;
global $table_ranges_create;
$table_ranges = "ts_ranges";
$table_ranges_create = "CREATE TABLE $table_ranges ( 
  rangeid bigint(20) unsigned NOT NULL auto_increment,
  name varchar(256) NOT NULL,
  address varchar(512) NOT NULL,
  phone varchar(11) NOT NULL,
  PRIMARY KEY  (rangeid)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC AUTO_INCREMENT=0; ";

global $table_shooters;
global $table_shooters_create;
$table_shooters = "ts_shooters";
$table_shooters_create = "CREATE TABLE $table_shooters (
  shooterid bigint(20) unsigned NOT NULL auto_increment,
  firstname varchar(64) NOT NULL,
  lastname varchar(64) NOT NULL,
  rangeid bigint(20) unsigned NOT NULL,
  categoryid bigint(20) unsigned NOT NULL,
  PRIMARY KEY  (shooterid),
  KEY rangeid (rangeid),
  KEY categoryid (categoryid),
  KEY name (firstname,lastname)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=0; ";

global $table_eventtypes;
global $table_eventtypes_create;
$table_eventtypes = "ts_eventtypes";
$table_eventtypes_create = "CREATE TABLE $table_eventtypes (
  eventtypeid bigint(20) unsigned NOT NULL auto_increment,
  name varchar(256) NOT NULL,
  PRIMARY KEY  (eventtypeid)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC AUTO_INCREMENT=0; ";

global $table_shoots;
global $table_shoots_create;
$table_shoots = "ts_shoots";
$table_shoots_create = "CREATE TABLE IF NOT EXISTS $table_shoots (
  shootid bigint(20) unsigned NOT NULL auto_increment,
  rangeid bigint(20) unsigned NOT NULL,
  name varchar(256) NOT NULL,
  date date NOT NULL,
  PRIMARY KEY  (shootid),  
  KEY rangeid (rangeid)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC AUTO_INCREMENT=0 ;";

global $table_events;
global $table_events_create;
$table_events = "ts_events";
$table_events_create = "CREATE TABLE $table_events (
  eventid bigint(20) unsigned NOT NULL auto_increment,
  shootid bigint(20) unsigned NOT NULL,
  eventtypeid bigint(20) unsigned NOT NULL,
  PRIMARY KEY  (eventid),
  KEY eventid (eventid), 
  KEY eventtypeid (eventtypeid),
  KEY shootid (shootid)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED AUTO_INCREMENT=0; ";

global $table_rounds;
global $table_rounds_create;
$table_rounds = "ts_rounds";
$table_rounds_create = "CREATE TABLE $table_rounds (
  roundid bigint(20) unsigned NOT NULL auto_increment,
  eventid bigint(20) unsigned NOT NULL,
  fieldid bigint(20) unsigned NOT NULL,
  shooterid bigint(20) unsigned NOT NULL,
  round1 int(32) unsigned NOT NULL,
  round2 int(32) unsigned NOT NULL,
  round3 int(32) unsigned NOT NULL,
  round4 int(32) unsigned NOT NULL,
  PRIMARY KEY  (roundid),
  KEY eventid (eventid), 
  KEY shooterid (shooterid),
  KEY fieldid (fieldid)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED AUTO_INCREMENT=0; ";

?>
